package com.bookocean.domain.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 书籍分类枚举
 */
@Getter
@AllArgsConstructor
public enum BookCategoryEnum {
    
    HISTORY(1, "历史"),
    LITERATURE(2, "文学"),
    TECHNOLOGY(3, "科技"),
    ART(4, "艺术"),
    PHILOSOPHY(5, "哲学"),
    NOVEL(6, "小说"),
    BIOGRAPHY(7, "传记"),
    EDUCATION(8, "教育"),
    OTHER(9, "其他");
    
    private final Integer code;
    private final String name;
    
    /**
     * 根据code获取枚举
     */
    public static BookCategoryEnum getByCode(Integer code) {
        for (BookCategoryEnum category : values()) {
            if (category.getCode().equals(code)) {
                return category;
            }
        }
        return OTHER;
    }
    
    /**
     * 根据name获取枚举
     */
    public static BookCategoryEnum getByName(String name) {
        for (BookCategoryEnum category : values()) {
            if (category.getName().equals(name)) {
                return category;
            }
        }
        return OTHER;
    }
}
